package com.distributeredis.redis_springboot.springbooteasyexcel.read.service.impl;

import com.distributeredis.redis_springboot.springbooteasyexcel.read.mapper.StudentMapper;
import com.distributeredis.redis_springboot.springbooteasyexcel.read.service.StudentService;
import com.distributeredis.redis_springboot.springbooteasyexcel.read.vo.Student;
import com.distributeredis.redis_springboot.springbooteasyexcel.read.vo.StudentExcelDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Slf4j
@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List<StudentExcelDTO> queryAllStudents() {
        List<Student> studentList = studentMapper.queryAllStudents();
        List<StudentExcelDTO> students = new ArrayList<>();
        studentList.forEach(item -> {
            StudentExcelDTO student = new StudentExcelDTO();
            BeanUtils.copyProperties(item, student);
            students.add(student);
        });
        return students;
    }
}
